package com.jy.print.javaprint.controller;

import com.jy.print.javaprint.pojo.HeatSealData;
import com.jy.print.javaprint.pojo.ProviderData;
import com.jy.print.javaprint.utils.AllotPrint;
import com.jy.print.javaprint.utils.HeatSealPrint;
import com.jy.print.javaprint.utils.QrCodeAndRemarkPrint;
import com.jy.print.javaprint.utils.QrCodePrint;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.net.URLDecoder;

@RestController
@RequestMapping("/javaPrint")
public class JavaPrint {

    /**
     *  热合打印
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping("/heatSealPrint")
    public String heatSealPrint(@RequestBody HeatSealData heatSealData) throws Exception {
        HeatSealPrint print = new HeatSealPrint(heatSealData);
        print.doPrint();
        return "sucess";
    }
    /**
     *  热合打印
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping("/heatSealPrintDemo")
    public String heatSealPrintDemo() throws Exception {
        HeatSealData heatSealData = new HeatSealData();
        heatSealData.setAge("16");
        heatSealData.setCardId("302001");//
        heatSealData.setName("杨云云");
        heatSealData.setSex("男");
        heatSealData.setXjbh("30219P001002805");
        heatSealData.setXjType("普通");
        heatSealData.setBloodType("A");
        heatSealData.setXjWeight("600");

        HeatSealPrint print = new HeatSealPrint(heatSealData);
        print.doPrint();
        return "sucess";
    }
    /**
     *  分配打印
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping("/allotPrint")
    public String allotPrint() throws Exception {
        ProviderData data = new ProviderData();
        data.setProviderNo("302115");
        data.setName("杨云云");
        data.setSex("男");
        data.setMachineCode("005");
        data.setNeedAssay(true);
        data.setXqdyId("302D19001-32");
        AllotPrint print = new AllotPrint( data);
        print.doPrint();
        return "sucess";
    }



    /**
     *  二维码打印
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping("/qrCodePrint")
    public String qrCodePrint(@RequestParam String qrCode) throws Exception {
        QrCodePrint print = new QrCodePrint(qrCode);
        print.doPrint();
        return "sucess";
    }
    /**
     *  二维码描述信息 + 二维码 打印
     * @param
     * @return
     * @throws Exception
     */
    @RequestMapping("/qrCodeAndRemarkPrint")
    public String qrCodeAndRemarkPrint(@RequestParam String qrCode,@RequestParam String remark) throws Exception {
//        System.out.println(qrCode);
//        System.out.println(remark);
//        qrCode = URLDecoder.decode(qrCode,"UTF-8");
//        remark = URLDecoder.decode(remark,"UTF-8");
//        System.out.println("-------------------------------------");
        System.out.println(qrCode);
        System.out.println(remark);
        QrCodeAndRemarkPrint print = new QrCodeAndRemarkPrint(qrCode,remark);
        print.doPrint();
        return "sucess";
    }
}
